﻿using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using OAProject.Domain.Interfaces;
using OAProject.Domain.Entities;
using Microsoft.AspNetCore.Authorization;


namespace OAProject.API.Controllers
{
    /// <summary>
    /// 菜单Api控制器
    /// </summary>
    [Route("api/[controller]/[action]")]
    [ApiController]
    [Authorize]     //全局授权过滤器
    public class MenusController : ControllerBase
    {
        //依赖注入
        private IMenusRepository _repository;
        private IRoleUsersrepository _roleUsersrepository;

        public MenusController(IMenusRepository repository,IRoleUsersrepository roleUsersrepository)
        {
            _repository = repository;
            _roleUsersrepository = roleUsersrepository;
        }

        /// <summary>
        /// 菜单显示
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public IActionResult GetIndex()
        {
            List<Menus> list = _repository.Show();
            
            return Ok(new
            {
                data = list,
                code=0
            });
        }

        /// <summary>
        /// 获取父级的菜单
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        [HttpGet]
        public List<Menus> GetFuMenu(int id)
        {
            List<Menus> roleUsers = _roleUsersrepository.GetParentMenu(id);
            return roleUsers;
        }
        /// <summary>
        /// 获取子级的菜单
        /// </summary>
        /// <param name="Pid"></param>   
        /// <returns></returns>
        [HttpGet]
        public List<Menus> GetZiMenu(int Pid)
        { 
            List<Menus> lst= _roleUsersrepository.GetChildMenu(Pid);
            return lst;
        }


    }
}
